Repository navigation
[experiment] Menu2 shared styles as layered styled components - #2
Draft
siriwatknp wants to merge 1 commit into
Draft
siriwatknp wants to merge 1 commit into
siriwatknp wants to merge 1 commit into
Conversation
Share menu item, popup slot, and indicator styles through nameless styled
bases instead of exported style objects and functions. Each family wraps a
base with its own theme name and slot, so theme keys and classes stay
isolated. Removes menuStyles.js, menuItemStyles.js, and menu2SharedStyles.ts.
Named wrappers forward ownerState so the base variants still match, and use
({}) instead of a zero-argument call: Pigment CSS 0.0.31 crashes on
styled(X, opts)(). The shared item base styles the highlight through
.Mui-focusVisible (classic) and [data-highlighted] (Base UI) in one selector.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Companion PoC for mui#48823, targeting its branch. Not intended to merge as-is — it demonstrates an alternative to the shared style modules for discussion.
What it does
Replaces the exported style objects/functions (
Menu/menuStyles.js,MenuItem/menuItemStyles.js,Unstable_Menu2/menu2SharedStyles.ts— all three deleted) with nameless shared styled components:MenuItem/MenuItemBase.tsx— all shared item styles + variants, onButtonBaseUnstable_Menu2/Menu2ItemBase.tsx— Menu2 delta (div resets, disabled pointer-events)Unstable_Menu2/Menu2PopupSlotBases.tsx— positioner/paper/list bases shared byMenu2PopupandMenu2SubmenuPopupUnstable_Menu2/Menu2IndicatorBase.tsx— shared by both indicatorsEach family wraps a base with its own
name/slot, so theme keys and classes stay isolated:This removes the
getMenuItemRootStyles(theme, classes, options)pattern: no class-map parameter, nofocusVisibleClass/disabledPointerEventsoption flags, nomemoThemeat call sites. ClassicMenuItem.js/Menu.jsend up close to their master state.How the class parameterization was resolved
selected/disabledstate classes are global (Mui-selected/Mui-disabled) — identical for every family.highlighted. The base styles it through one dual selector:&.Mui-focusVisible(classic, from ButtonBase focus tracking) and&[data-highlighted](Base UI attribute). At most one matches per family. This is the main contract question: the highlight visual now keys on a Base UIdata-*attribute rather than the family class.Verified
tscclean, ESLint clean, 350 unit tests pass (jsdom scope), including thedescribeConformancestyleOverrides/variant assertions that exercise theownerStateforwarding.@wyw-in-js/transform) on a fixture mirroring this exact shape — cross-file layered composition, function-prop variants, and the dual selector all extract correctly. One caveat found: a zero-argumentstyled(X, opts)()crashes the Pigment processor, so the wrappers use({}).Trade-offs to weigh
ownerState(shouldForwardProp) — forgetting it silently disablesdense/divider/guttersfor that family. ConformancetestVariantPropscatches thedensecase.[data-highlighted]styling dependency vs the RFC's "Mui-* classes are the public contract" rule needs an explicit decision.Also observed while extracting: once
maxHeightdiverged, the classic and Menu2 popups genuinely share onlyWebkitOverflowScrolling: touch— the real popup-style sharing is betweenMenu2PopupandMenu2SubmenuPopup. The classic Menu paper/list styles are inlined back intoMenu.js.